---
feature_name: Array Method includes (ES7)
chrome_version: 47
feature_id: 5964420647747584
---

<h3>Background</h3>
<p>
  To determine if an array includes an element, we could use the popular <code>if
    (arr.indexOf(el) !== -1)</code> pattern which exhibits two problems: It fails to
  "say what you mean", and also fails for <code>NaN</code>, as <code>indexOf</code> uses <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness">Strict Equality
  Comparison</a> and thus <code>[NaN].indexOf(NaN) === -1</code>.
</p>
<p>
  The new <a href='https://tc39.github.io/Array.prototype.includes/'><code>Array.prototype.includes</code></a>
  method is an ECMAScript 2016 (ES7) proposal. It can be used to determine
  whether an array includes a given element in an elegant way.
</p>
<p>
  It compares first arguments to the elements of the array, in ascending order,
  using the <a href='https://github.com/tc39/Array.prototype.includes/blob/master/README.md#why-samevaluezero'>SameValueZero algorithm</a>
  and if found at any position, returns <code>true</code>; otherwise,
  <code>false</code> is returned.
</p>
<p>
  The optional second argument <code>fromIndex</code> defaults to
  <code>0</code> (i.e. the whole array is searched). If it is negative, it is
  used as the offset from the end of the array to compute
  <code>fromIndex</code>.
</p>

{% include output_helper.html %}

{% include js_snippet.html filename='demo.js' %}
